<?php
require_once("../../controllers/init.php");
//echo "Filesystem root = ".$FILE_SYSTEM_ROOT."\n<br>";
require_once($FILE_SYSTEM_ROOT."/controllers/authentication.php");
//echo "logged on - ".(($IS_LOGGED_ON)?"true\n":"false\n");
require_once($FILE_SYSTEM_ROOT."/model/classes/events/EventsResultSet.php");


/*$from = new DateTime("2012/01/01");*/
$from = new DateTime("now");
$from->modify("-1 month");
$to = new DateTime("now");
$to->modify("+6 month");


//echo "<p>Logged on = ".$IS_LOGGED_ON."<p>\n";
echo "<p>Choose a report from the menu above.</p>\n";
echo "<p>Only events from the past month and the forthcoming six months are displayed.</p>\n";


$InvolveeType=0;

if(!isset($_POST['Type'])) exit();
elseif($_POST['Type']=='events')$InvolveeType = 13;
elseif($_POST['Type']=='catering')$InvolveeType = 10;
elseif($_POST['Type']=='invoice')$InvolveeType = 11;
elseif($_POST['Type']=='publicity')$InvolveeType = 7;
elseif($_POST['Type']=='vergers')$InvolveeType = 17;

$events = new EventsResultSet();

$sql="SELECT DISTINCT Events.EventID FROM Events INNER JOIN EventInvolvees ON Events.EventID = EventInvolvees.EventID";  
$sql .= " WHERE Events.Start>='".$from->format("Y-m-d");
$sql .= "' AND Events.Start<'".$to->format("Y-m-d");
$sql .= "' AND Events.DeletedBy=0 ";

if($_POST['Type']=='music')
{
	$sql .= " AND ";
	$sql .= "(EventInvolvees.EventInvolveeNameID=1 "; // 1 is Men
	$sql .= " OR EventInvolvees.EventInvolveeNameID=2 "; // 2 is Boys
	$sql .= " OR EventInvolvees.EventInvolveeNameID=3 "; // 3 is Girls
	$sql .= " OR EventInvolvees.EventInvolveeNameID=4 "; // 4 is Consort
	$sql .= " OR EventInvolvees.EventInvolveeNameID=5 "; // 5 is Lanterns
	$sql .= " OR EventInvolvees.EventInvolveeNameID=6 "; // 6 is Website
	$sql .= " OR EventInvolvees.EventInvolveeNameID=14 ) "; // 14 is Music required
		}
else 
{
	$sql .= " AND EventInvolvees.EventInvolveeNameID=".$InvolveeType; // 13 is events 10 is catering 17 is vrergers and 11 is invoice
}
$sql .= " ORDER BY Events.Start";

//echo "<p>".$sql."</p>\n";

$events->setSQL($sql);

$results = $events->getEvents();

echo "<div id=\"calendar-month-event-edit\"></div>\n";


echo "<div id=\"reports-events\">\n";
echo "<div class=\"reports-events-event\">\n";
echo "<div class=\"reports-events-title reports-events-event-date\">Date</div>\n";
echo "<div class=\"reports-events-title reports-events-event-start\">Start</div>\n";
echo "<div class=\"reports-events-title reports-events-event-end\">End</div>\n";
echo "<div class=\"reports-events-title reports-events-event-title\">Title</div>\n";
echo "<div class=\"reports-events-title reports-events-event-description\">Description</div>\n";
echo "<div class=\"reports-events-title reports-events-event-comments\">Comments</div>\n";
echo "<div class=\"reports-events-title reports-events-event-responsible\">Responsible</div>\n";
echo "<div class=\"reports-events-title reports-events-event-involvees\">Involving</div>\n";
echo "<div class=\"reports-events-title reports-events-event-locations\">Locations</div>\n";
if($_POST['Type']=='music') 
	echo "<div class=\"reports-events-title reports-events-event-live\">Live</div>\n";
echo "<div class=\"reports-events-title reports-events-event-type\">Type</div>\n";
echo "</div>\n";
	
echo "<div id=\"reports-events\">\n";


foreach($results as $event)
{
	echo "<div class=\"reports-events-event\">\n";
	echo "<div class=\"reports-events-event-id\">".$event->getEventID()."</div>\n";
	echo "<div class=\"reports-events-event-date\">".$event->getStart()->format("D M d Y")."</div>\n";
	echo "<div class=\"reports-events-event-start\">".$event->getStart()->format("H:i")."</div>\n";
	echo "<div class=\"reports-events-event-end\">".$event->getEnd()->format("H:i")."</div>\n";
	echo "<div class=\"reports-events-event-title\">".$event->getTitle()."</div>\n";
	echo "<div class=\"reports-events-event-description\">".$event->getDescription()."</div>\n";
	echo "<div class=\"reports-events-event-comments\">".$event->getComment()."</div>\n";
	echo "<div class=\"reports-events-event-responsible\">".$event->getResponsible()."</div>\n";
	echo "<div class=\"reports-events-event-involvees\">".$event->getInvolveesList()."</div>\n";
	echo "<div class=\"reports-events-event-locations\">".$event->getLocationsList()."</div>\n";
	$livetext="";
	if($_POST['Type']=='music') 
	{
		
		$livetext=($event->getLive()==1)?"Live":"Not live";
		echo "<div class=\"reports-events-event-live\">".$livetext."</div>\n";
	}
	echo "<div class=\"reports-events-event-type\">".$EVENTTYPES[$event->getTypeID()]."</div>\n";
	echo "</div>\n";
}

echo "</div>\n";


